<?php
/**
 * Created by PhpStorm.
 * User: kamlyli
 * Date: 2017/8/5
 * Time: 11:21
 */

namespace app\api\controller\v1;


use app\api\model\User;
use think\Controller;
use think\Request;

class Base extends Controller
{
    protected $userId;
    protected $openId;

    public function check_cookie()
    {
        $request = Request::instance();
        $header = $request->header();
        if (!$header['_aq']) {
            return;
        }

        $header_aq = message_decrypt($header['_aq']);
        if (!$header_aq) {
            return;
        }

        // 有没有这个人
        $user = new User();
        $user = $user->where(['id' => $header_aq['id'], 'openId' => $header_aq['openId']])->find();
        if (!$user) {
            return;
        }

        $this->userId = $user->id;
        $this->openId = $user->openId;
    }
}